package Flink.transformation;

import Flink.bean.WaterSensor;
import Flink.function.UserFilter;
import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class FilterTrans {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<WaterSensor> streamSource = env.fromElements(
                new WaterSensor("sensor_1", 1L, 1),
                new WaterSensor("sensor_2", 1L, 2),
                new WaterSensor("sensor_3", 1L, 1),
                new WaterSensor("sensor_4", 1L, 3)
        );
        // 方式一：传入匿名类实现FilterFunction
        streamSource.filter(new FilterFunction<WaterSensor>() {
            @Override
            public boolean filter(WaterSensor value) throws Exception {
                return value.getVc() == 1;
            }
        }).print();
        // 方式二：传入FilterFunction实现类
//        streamSource.filter(new UserFilter()).print();

        env.execute();
    }


}
